package com.anlu.base.mapper;

import com.anlu.base.mapper.mappermodel.UserDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2024/9/23 11:20
 */
// @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE )
public interface UserConvert {

    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    @Mapping(source = "id",target = "userId",constant = "可以指定常量")
    // 默认值
    @Mapping(source = "name", target = "userName", defaultValue = "可以指定默认值")
    // 日期转换
    @Mapping(source = "crateTime", target = "beginTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    UserDTO userToUserDto(com.anlu.base.model.User user);


    @Mappings({
            @Mapping(source = "id", target = "userId",numberFormat = "$#.00"),
            @Mapping(source = "name",target = "userName"),
            @Mapping(source = "beginTime",target = "createTime",dateFormat = "yyyy-MM-dd "),
            //使用Java可以执行的函数或者代码
            @Mapping(target = "beginTime",expression = "java(java.time.LocalDateTime.now()")
    })
    UserDTO userToUserDto2(com.anlu.base.model.User user);


    //批量循环，循环调用上面的单个转换
    List<UserDTO> userToUserDtoList(List<com.anlu.base.model.User> users);



}
